package com.piggy.auth.controller;

import com.piggy.auth.bo.OAuthReqPhone;
import com.piggy.auth.bo.OAuthReqPwd;
import com.piggy.auth.bo.OAuthRes;
import com.piggy.auth.bo.OAuthResetPwd;
import com.piggy.auth.services.LogiSysLoginService;
import com.piggy.common.core.domain.R;
import com.piggy.logi.sys.api.domain.LogiSysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * token 控制
 *
 * @author shark
 */
@Api(value="物流系统",tags = {"登录认证"})
@RestController
@RequiredArgsConstructor
@RequestMapping("/logi/oauth")
public class LogiTokenController
{

    @Resource
    private LogiSysLoginService loginService;

    /**
     * 令牌管理调用
     * @return
     */
    @ApiOperation("验证码登录")
    @PostMapping("/login")
    public R<OAuthRes> oauth(@RequestBody OAuthReqPwd oauth) {
        return R.ok(loginService.login(oauth));
    }

    /**
     * 令牌管理调用
     * @return
     */
    @ApiOperation("注册登录")
    @PostMapping("/register")
    public R<LogiSysUser> register(@RequestBody OAuthReqPhone oauth) {
        return loginService.register(oauth);
    }

    /**
     * 令牌管理调用
     * @return
     */
    @PostMapping("/logout")
    public R<Boolean> logout() {
        return R.ok(loginService.logout());
    }

    /**
     * 踢人
     * @return
     */
    @PostMapping("/kickout")
    public R<Boolean> kickout(@RequestBody OAuthReqPwd oauth) {
        return R.ok(loginService.kickout(oauth));
    }

    /**
     * 重置服务商用户密码
     * @return
     */
    @ApiOperation("重置服务商用户密码")
    @PostMapping("/resetMainUserPwd")
    public R<Boolean> resetMainUserPwd(@RequestBody OAuthResetPwd oauth) {
        return R.ok(loginService.resetMainUserPwd(oauth));
    }

    /**
     * 验证手机号码
     * @return
     */
    @ApiOperation("验证码认证")
    @GetMapping("/verify")
    public R<Boolean> verify(String phone, String verifyCode) {
        return loginService.verify(phone, verifyCode);
    }

    /**
     * 查询服务商主账号
     * @return
     */
    @ApiOperation("查询服务商主账号")
    @GetMapping("/getMainUser/{phone}")
    public R<LogiSysUser> getMainUser(@PathVariable("phone")String phone) {
        return loginService.getMainUser(phone);
    }

}
